﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using AfvandingService;
using System.Web.UI.WebControls;
using System.Net;
using System.ServiceModel;

namespace AfvandingKlient
{
    public partial class OpretPumpeStation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsCallback)
            {
                List<string> temp = new List<string>();
                temp.Add("Kritisk");
                temp.Add("Høj");
                temp.Add("Mellem");
                temp.Add("Lav");
                dropdownVandstandsrisiko.DataSource = temp;
            }
            DataBind();

            if (Session["OpdatérEllerOpret"].ToString() == "Opdatér")
            {
                txtboxPumpestationsNr.Text = Session["PSnummer"].ToString();
                txtboxPumpestationsNr.Enabled = false;
                RFVPumpestationsnr.Enabled = false;
                _pageHeader.Text = "Opdatér Pumpestation";
            }
        }

        protected void btnOpretPumpestation_Click(object sender, EventArgs e)
        {
            ChannelFactory<ICentral> proxy = (ChannelFactory<ICentral>)Session["proxy"];
            ICentral central = proxy.CreateChannel();
            string OpdatérEllerOpret = Session["OpdatérEllerOpret"].ToString();

            if (OpdatérEllerOpret == "Opret")
            {
                central.OpretPumpestation(int.Parse(txtboxPumpestationsNr.Text), txtboxNetværksadresse.Text, txtboxIP.Text,
                                      int.Parse(txtboxPort.Text), dropdownVandstandsrisiko.SelectedValue, double.Parse(txtboxVandstand.Text));
                Response.Redirect("CentralSystem.aspx");
            }

            else if (OpdatérEllerOpret == "Opdatér")
            {
                central.OpdatérPumpestation((int)Session["PSnummer"], txtboxNetværksadresse.Text, txtboxIP.Text, 
                                            int.Parse(txtboxPort.Text), dropdownVandstandsrisiko.SelectedValue, double.Parse(txtboxVandstand.Text));
                Response.Redirect("CentralSystem.aspx");
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("CentralSystem.aspx");
        }
    }
}